#ifndef UI_MENU_GENERIC_H_
#define UI_MENU_GENERIC_H_

#include "ui_base.h"

#include <map>

class CUIMenuGeneric : public CUIBase
{
	
	std::map< int, std::string > m_vOptions;
	std::map< int, std::string >::iterator m_OptionIter;
	
	int m_NumOptions;
	int m_CurOption;
	
	bool m_bSelected;
	
	CFontMaterial * m_ChosenFontMat;
	
	bool m_bCascade;

public:

	CUIMenuGeneric() : CUIBase(), m_CurOption( 0 ), m_ChosenFontMat( NULL ), m_NumOptions( 0 ), m_bSelected( false ), m_bCascade( false )
	{ 
		
	}
	
	void Input( SDL_Event &, Uint8 * );
	void Draw();
	
	inline void Cascade()
	{
		
		m_bCascade = true;
		
	}
	
	inline int PollSelected()
	{
		
		if( m_bSelected )
		{
			
			m_bSelected = false;
			return m_CurOption;
			
		}
		
		return -1;
		
	}
	
	inline void GoUp()
	{
		
		if( m_OptionIter == m_vOptions.begin() )
			m_OptionIter = m_vOptions.end();
		
		m_OptionIter--;
		
	}
	
	inline void GoDown()
	{
		
		m_OptionIter++;
		
		if( m_OptionIter == m_vOptions.end() )
			m_OptionIter = m_vOptions.begin();
		
	}
	
	inline void SetChosenFont( CFontMaterial * font )
	{
		
		m_ChosenFontMat = font;
		
	}
	
	inline void SetOptionText( int key, std::string text )
	{
		
		m_vOptions[key] = text;
		
	}
	
	inline void ResetOptions()
	{
		
		m_SizeOverride.SetXY( 0, 0 );
		
		m_vOptions.clear();
		
		m_OptionIter = m_vOptions.end();
		
		m_NumOptions = 0;
		m_CurOption = 0;
		
	}
	
	inline void AddOption( int key, std::string option )
	{
			
		m_vOptions[key] = option;
	
	
		if( !m_CurOption )
		{
			
			m_CurOption = key;
			m_OptionIter = m_vOptions.begin();
			
		}
		
		int w = m_FontMat->GetStringWidth( option );
		
		if( w > m_SizeOverride.x )
			m_SizeOverride.x = w;
		
		m_SizeOverride.y += m_Padding.y + m_FontMat->GetHeight();
		
		m_NumOptions++;
		
		
	}

};

#endif
